home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3919 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  56 lines

  1. Newsgroups: comp.lang.c++
  2. Path: lynx.cs.washington.edu!xyu
  3. From: Xuri Yu <xyu@lynx.cs.washington.edu>
  4. Subject: Help! design of quadtree!!
  5. Content-Type: TEXT/PLAIN; charset=US-ASCII
  6. Sender: news@beaver.cs.washington.edu (USENET News System)
  7. Organization: Computer Science & Engineering, U of Washington, Seattle
  8. Message-ID: <Pine.ULT.3.91.960126093647.13952A-100000@lynx.cs.washington.edu>
  9. Mime-Version: 1.0
  10. X-Nntp-Posting-Host: lynx.cs.washington.edu
  11. Date: Fri, 26 Jan 1996 17:40:38 GMT
  12.  
  13. Hello,
  14.  
  15.   I try to define the data structure of quadtree as follows:
  16.  
  17. class quadnode {
  18. protected:  
  19.  
  20. struct subnode {
  21.   float avgdata;
  22.   quadnode *child[2];
  23.  
  24.   subnode() { for (int i=0; i<2; i++) child[i] = new quadnode[2]; } 
  25. };
  26.  
  27.  
  28.   union {
  29.     float data;
  30.     subnode *nextquad;
  31.   };
  32.  
  33.  
  34. public:
  35.   quadnode(subnode *quad = NULL): nextquad(quad) {}
  36.   quadnode(float x): data(x) {}
  37.        
  38.        
  39.   friend class quadtree;
  40. };
  41.  
  42.  
  43. class quadtree {
  44. protected:
  45.   quadnode root;
  46.  ...
  47. };
  48.  
  49.  
  50. The purpose of using 'union' is to save memory. The design doesn't work 
  51. well. Could anyone solve this problem? Thanks a lot.
  52.  
  53.  
  54. Zuri
  55.  
  56.